package thread;
//继承自Thread能直接通过this获取线程实例
//如若采用Runnable lambda表达式写法 this不再指向Thread对象
//只能使用Thread.currentThread();
class MyThread4 extends Thread{
    @Override
    public void run() {
        System.out.println(this.getId()+","+this.getName());
    }
}

public class Thread_get {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new MyThread4();
        Thread t2 = new MyThread4();
        t1.start();
        t2.start();
        Thread.sleep(1000);
        System.out.println(t1.getId()+","+t1.getName());
        System.out.println(t2.getId()+","+t2.getName());
        //通过增强for循环获取线程状态
        for (Thread.State state : Thread.State.values()){
            System.out.println(state);
        }
    }
}
